import React from 'react';
import loadjs from 'loadjs';
import * as file from '../../constants/fileConfig';
import Loading from '../../asyncComps/Loading';

export default class Main extends React.Component{
    constructor(){
        super();
        this.state = {
            hasLoad: false
        };
    }
    componentDidMount() {
        //按顺序加载依赖的异步JS
        const fileList = file.antdFiles.concat(file.ecComFiles);
        loadjs(fileList, {
            async: false,
            success: () =>{
                this.setState({hasLoad: true});
            }
        });
    }
    render(){
        const {hasLoad} = this.state;
        if (hasLoad) {
            const location = this.props.location || {};
            const isBatch = location.query && location.query.isBatch == "1";
            const Print = isBatch ? require("./BatchPrint").default : require("./PrintReq").default;
            return (<Print ecId={`${this && this.props && this.props.ecId || ''}_Print@rz9egp`} {...this.props} />);
        }else{
            return (<Loading ecId={`${this && this.props && this.props.ecId || ''}_Loading@hby7ea`} />);
        }
    }
}